package edu.zut.cs.network.exercise.practice.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.naming.spi.DirStateFactory.Result;

public class JdbcExample {

	Connection conn = null;
	String PASSWORD = "zutnlp";
	Result result = null;
	Statement st = null;
	ResultSet rs = null;
	String URL = "jdbc:mysql://202.196.37.91:3306/course?useUnicode=true&amp;characterEncoding=utf-8";
	String USER = "zutnlp";

	public void query() {

		try {
			try {
				Class.forName("com.mysql.jdbc.Driver");
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			conn = DriverManager.getConnection(URL, USER, PASSWORD);
			st = conn.createStatement();
			rs = st.executeQuery("select id,fullname from t_student");
			while (rs.next()) {
				System.out.println(rs.getString(1) + " " + rs.getString(2));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				rs.close();
				st.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JdbcExample jdbcExample = new JdbcExample();
		jdbcExample.query();
	}

}
